gui/macOS: Add convenience inline methods to check if VFS domain identifier is illega...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 10 Feb 2025 07:06:43 +0000 (15:06 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 10 Feb 2025 11:01:06 +0000 (12:01 +0100)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/fileproviderdomainmanager_mac.mm

index b75c59bf7abeee93cb9ddc611bb0da1b693a9216..d1660810a18afd9edfeaba7f21f5f256382f5176 100644 (file)
@@ -43,6 +43,19 @@ static constexpr auto bundleExtensions = std::array{
     QLatin1StringView(".saver"),
     QLatin1StringView(".mdimporter")
 };
+static const QRegularExpression illegalChars("[:/]");
+
+inline bool hasBundleExtension(const QString &domainId)
+{
+    return std::any_of(bundleExtensions.begin(), bundleExtensions.end(), [&domainId](const auto &ext) {
+        return domainId.endsWith(ext);
+    });
+}
+
+inline bool illegalDomainIdentifier(const QString &domainId)
+{
+    return !domainId.isEmpty() && !illegalChars.match(domainId).hasMatch() && hasBundleExtension(domainId);
+}
 
 QString domainIdentifierForAccount(const OCC::Account * const account)
 {
@@ -50,7 +63,6 @@ QString domainIdentifierForAccount(const OCC::Account * const account)
     auto domainId = account->userIdAtHostWithPort();
     Q_ASSERT(!domainId.isEmpty());
 
-    static const QRegularExpression illegalChars("[:/]");
     domainId.replace(illegalChars, "-");
 
     // Some url domains like .app cause issues on macOS as these are also bundle extensions.